<?php

namespace app\common\model;

use think\Model;

class GroupModel extends Model
{
    //
    protected $resultSetType = 'collection';
    public
        $table = 'cms_blog_group',
        $pk = 'id';

    public function updateData($param)
    {

        $data = [
            'mark' => $param['mark'],
            'name' => $param['name'],
            'center_permit' => json_encode($param['center_permit']),
            'description' => $param['description'],
        ];
        if (!empty($param['id'])) {
            $data['update_time'] = time();
            $sql = $this->save($data, ['id' => $param['id']]);
            if ($sql) {
                return ['status' => 1, 'message' => '修改成功'];
            } else {
                return ['status' => 0, 'message' => '修改失败'];
            }
        } else {
            $data['create_time'] = time();
            $sql = $this->insert($data);
            if ($sql) {
                return ['status' => 1, 'message' => '添加成功'];
            } else {
                return ['status' => 0, 'message' => '添加失败'];
            }
        }
    }

    public function getGroupInfo($where)
    {
        return $this->where($where)->find();
    }

    public function del($id)
    {
        try {
            $data = $this->destroy($id);
            if ($data) {
                return ['status' => 1, 'message' => '删除成功'];
            } else {
                return ['status' => 0, 'message' => '删除失败'];
            }
        } catch (\Exception $e) {
            echo $e->getMessage();
        }

    }
}
